Skip to content

fix: normalize all routing prefixes in pricing lookup#13

Open
Sagargupta16 wants to merge 8 commits intomm65x:masterfrom
Sagargupta16:fix/pricing-prefix-normalization
Open

fix: normalize all routing prefixes in pricing lookup#13
Sagargupta16 wants to merge 8 commits intomm65x:masterfrom
Sagargupta16:fix/pricing-prefix-normalization

Conversation

@Sagargupta16
Copy link
Copy Markdown

Summary

  • Fix find_pricing to strip all routing prefixes before pricing lookup, not just vertexai.
  • Resolves pricing discrepancies when the same model is accessed via different providers

Root cause

find_pricing (cost.rs:147) only stripped the vertexai. prefix before looking up model pricing. Models from Bedrock (bedrock/anthropic.claude-*), OpenAI-compatible clients (openai/), or deployments (model@deploy) kept their routing prefix, causing lookup failures or fallback to prefix matching that could resolve to wrong pricing.

Meanwhile, display::strip_routing_prefix already handled all these cases correctly for display purposes -- it just wasn't being used in the pricing path.

Changes

  • cost.rs: Reuse display::strip_routing_prefix in find_pricing to strip all routing prefixes (slash-based, dot-based, @Deploy suffixes) before the lookup cascade
  • cost.rs: Apply the same stripping in normalize_model_name so normalized lookups also work for prefixed models
  • display.rs: Make strip_routing_prefix public for cross-module use
  • tests: Add test_find_pricing_cross_provider_same_model verifying the same model resolves to identical pricing across 5 provider variants
  • tests: Add test_find_pricing_strips_deploy_suffix for @Deploy handling

Test plan

  • New test: same model via bare name, anthropic/, vertexai., bedrock/anthropic., openai/ all resolve to identical pricing
  • New test: @Deploy suffix is stripped before lookup
  • Existing tests should still pass (no Rust toolchain locally -- CI will verify)

Fixes #9

mm65x added 4 commits March 12, 2026 22:38
- Fixed an issue where the history sub-rows aggressively hardcoded the `Client` column to an empty string.
- The history mode now routes through the exact same `GroupBy` matcher logic as the normal view, dynamically showing or hiding the Model/API/Client headers completely symmetrically with the main TUI tables.
- Regroups the atomic models inside each historical period summary dynamically when the user cycles the `g` grouping hotkey.
@mm65x
Copy link
Copy Markdown
Owner

mm65x commented Mar 16, 2026

Thanks for putting this together. The logic changes to reuse strip_routing_prefix are exactly what we need to solve the pricing lookup issue.

It looks like there is a small syntax error at the bottom of src/cost.rs, though. The new tests (test_find_pricing_cross_provider_same_model and test_find_pricing_strips_deploy_suffix) were pasted twice, and they appear to be placed outside the closing brace of the mod tests block.

Could you clean up the duplicated lines and ensure the new tests are inside the test module? Once the CI is green, we can get this merged.

@Sagargupta16
Copy link
Copy Markdown
Author

Fixed -- removed the duplicate tests and added the missing closing brace. Should be clean now.

@mm65x
Copy link
Copy Markdown
Owner

mm65x commented Mar 20, 2026

close but there's still one extra closing brace on line 371 of src/cost.rs that breaks compilation. just delete that line and it should be good to go

@Sagargupta16
Copy link
Copy Markdown
Author

Fixed -- removed the extra closing brace on line 371. CI should be green now.

@mm65x
Copy link
Copy Markdown
Owner

mm65x commented Mar 21, 2026

clippy failure is from an outdated base - rebase on latest develop and it should pass

@Sagargupta16 Sagargupta16 force-pushed the fix/pricing-prefix-normalization branch from dc03b60 to 1e8a2b7 Compare March 22, 2026 00:58
@Sagargupta16
Copy link
Copy Markdown
Author

Rebased and squashed into a single clean commit. The extra brace was already removed in the previous push -- just cleaned up the history now.

@mm65x
Copy link
Copy Markdown
Owner

mm65x commented Mar 22, 2026

sorry, that was on our end - just pushed a fix to develop. one more rebase should do it

mm65x and others added 2 commits March 22, 2026 13:49
* fix: re-price records with zero cost instead of preserving them

Source parsers (e.g. OpenCode) store cost: 0 for models they can't price.
The apply_costs guard treated Some(0.0) as 'already priced', permanently
locking these records at $0. Now only positive costs are preserved.

* fix: stop silently truncating files on I/O errors and log skipped rows

- Changed map_while(Result::ok) to filter_map with error counters in
  claude_code.rs, pi_agent.rs, and jsonl_source.rs so a single bad line
  doesn't abort the entire file parse.
- Added skip counter to mark_preserved in cache.rs for row-level errors.

---------

Co-authored-by: mm65x <mm65x@users.noreply.github.com>
Reuse strip_routing_prefix from display.rs to remove provider-specific
prefixes (vertexai., bedrock/, openai/, azure/) before pricing lookup.
Previously only vertexai. was stripped, causing misses for other
providers.

Also strip @deployment suffixes so hosted deployments like
gpt-4o@my-deployment resolve correctly.
@Sagargupta16 Sagargupta16 force-pushed the fix/pricing-prefix-normalization branch from 1e8a2b7 to f4699f8 Compare March 22, 2026 23:34
@Sagargupta16
Copy link
Copy Markdown
Author

Rebased onto latest develop -- resolved the conflict with the new zero-cost repricing test. All three test additions are intact. Should be clean now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate pricing discrepancies for the same model across different API clients

2 participants